using System;
using System.Collections.Generic;
using System.Text;
using AF_ORM.CORE;
using System.Data;
using Bussiness.Entity;
using System.Data.SqlClient;
namespace Bussiness.Manager
{


    public class PT_ServiceListManager : Bussiness.ManagerBase.PT_ServiceListManagerBase
    {
        public static PT_ServiceListManager CreateInstant()
        {
            return new PT_ServiceListManager();
        }

        public DataTable GetServiceList()
        {
            string sql = "select ServiceCode,servicecode + '-' + serviceName  as ServiceName from PT_ServiceList where isdeleted = 0";
            return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql);
        }
        public PT_ServiceListEntity GetByID(int ID)
        {
            List<PT_ServiceListEntity> lst = SelectByIdLST(ID);
            if (lst != null && lst.Count > 0)
                return lst[0];
            return null;
        }
        public PT_ServiceListEntity GetByServiceCode(string ServiceCode)
        {
            List<PT_ServiceListEntity> lst = SelectByServiceCodeLST(ServiceCode);
            if (lst != null && lst.Count > 0)
                return lst[0];
            return null;
        }
        public bool DeleteAll()
        {
            string sql = "Delete From PT_ServiceList";
            if (SqlHelper.ExecuteNonQuery(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql) > 0)
            {
                sql = "Delete From PT_Service_Model";
                if (SqlHelper.ExecuteNonQuery(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql) > 0)
                    return true;
            }
            return false;
        }
        public DataTable GetAll()
        {
            string sql = @"SELECT s.*,sm.ModelCode, sm.AgentPrice,sm.Price
                           FROM PT_ServiceList s INNER JOIN PT_Service_Model sm ON s.ServiceCode= sm.ServiceCode AND s.IsDeleted=0 
                           ORDER BY s.ServiceCode";
            return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql);
        }
        public DataTable GetAll2()
        {
            string sql = @"SELECT s.*
                           FROM PT_ServiceList s 
                           ORDER BY s.ServiceCode";
            return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql);
        }
        public DataTable GetByService_Model(string serviceCode,string ModelCode)
        {
            string sql = @"SELECT s.*,sm.ModelCode, sm.AgentPrice,sm.Price
                           FROM PT_ServiceList s INNER JOIN PT_Service_Model sm ON s.ServiceCode= sm.ServiceCode AND s.IsDeleted=0 
                           WHERE sm.ServiceCode=@ServiceCode AND sm.ModelCode=@ModelCode
                           ORDER BY s.ServiceCode";
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@ServiceCode", serviceCode);
            param[1] = new SqlParameter("@ModelCode", ModelCode);
            return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql, param);
        }
        public DataTable SearchByServiceAndModel(string serviceCode, string ModelCode)
        {
            string sql = "SearchServiceList";
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@serviceCode", serviceCode);
            param[1] = new SqlParameter("@modelCode", ModelCode);
            return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, sql, param);
        }
    }
}
                    
